home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / GDEVLBP8.C < prev    next >
C/C++ Source or Header  |  1991-08-08  |  4KB  |  111 lines

  1. /* Copyright (C) 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gdevlbp8.c */
  21. /* Canon LBP-8II driver for Ghostscript */
  22. #include "gdevprn.h"
  23.  
  24. #define X_DPI 300
  25. #define Y_DPI 300
  26. #define LINE_SIZE ((X_DPI * 85 / 10 + 7) / 8)    /* bytes per line */
  27.  
  28. /* The device descriptors */
  29. private dev_proc_print_page(lbp8_print_page);
  30.  
  31. gx_device_printer gs_lbp8_device =
  32.   prn_device(prn_std_procs, "lbp8",
  33.     83,                /* width_10ths, 8.3" */
  34.     117,                /* height_10ths, 11.7" */
  35.     X_DPI, Y_DPI,
  36.     0.16, 0.20, 0.32, 0.20,        /* margins */
  37.     1, lbp8_print_page);
  38.  
  39. /* ------ Internal routines ------ */
  40.  
  41. #define ESC 0x1b
  42. #define CSI 0233
  43. static char can_inits[] = { ESC, ';', ESC, 'c', ESC, ';', /* reset, ISO */
  44.                             CSI, '2', '&', 'z', /* fullpaint mode */
  45.                             CSI, '1', '4', 'p', /* select page type (A4) */
  46.                             CSI, '1', '1', 'h', /* set mode */
  47.                             CSI, '7', ' ', 'I', /* select unit size (300dpi)*/
  48.                           };
  49.  
  50.  
  51. /* Send the page to the printer.  */
  52. private int
  53. lbp8_print_page(gx_device_printer *pdev, FILE *prn_stream)
  54. {    char data[LINE_SIZE*2];
  55.     char *out_data;
  56.     int out_count;
  57.  
  58. #define CSI_print(str) fprintf(prn_stream, str, CSI)
  59. #define CSI_print_1(str,arg) fprintf(prn_stream, str, CSI, arg)
  60.  
  61.                                 /* initialize */
  62.         fwrite(can_inits, sizeof(can_inits), 1, prn_stream);
  63.  
  64.     /* Send each scan line in turn */
  65.        {    int lnum;
  66.         int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  67.         byte rmask = (byte)(0xff << (-pdev->width & 7));
  68.  
  69.         for ( lnum = 0; lnum < pdev->height; lnum++ )
  70.            {    char *end_data = data + LINE_SIZE;
  71.             gdev_prn_copy_scan_lines(pdev, lnum,
  72.                          (byte *)data, line_size);
  73.                /* Mask off 1-bits beyond the line width. */
  74.             end_data[-1] &= rmask;
  75.             /* Remove trailing 0s. */
  76.             while ( end_data > data && end_data[-1] == 0 )
  77.                 end_data--;
  78.             if ( end_data != data )
  79.                {    
  80.                                 int num_cols = 0;
  81.  
  82.                     out_data = data;
  83.                                 while(out_data < end_data && *out_data == 0)
  84.                                   {
  85.                                     num_cols += 8;
  86.                                     out_data++;
  87.                                   }
  88.                                 out_count = end_data - out_data;
  89.  
  90.                                 /* move down */
  91.                                 CSI_print_1("%c%dd", lnum);
  92.                                 /* move across */
  93.                                 CSI_print_1("%c%d`", num_cols);
  94.  
  95.                                 /* transfer raster graphics */
  96.                                 fprintf(prn_stream, "%c%d;%d;300;.r",
  97.                                         CSI, out_count, out_count);
  98.  
  99.                                 /* send the row */
  100.                                 fwrite(out_data, sizeof(char),
  101.                                        out_count, prn_stream);
  102.                }
  103.            }
  104.     }
  105.  
  106.     /* eject page */
  107.         fprintf(prn_stream, "%c=", ESC);
  108.  
  109.     return 0;
  110. }
  111.